#include <iostream>
#include <string>
#include <memory>
#include <list>
#include <algorithm>

using namespace std;

/*
\ brief:   学生
\ author: 清晨与猫鱼
*/
class StudentVO {
public:
    explicit StudentVO(string name, int rollNo)
        : name_(move(name)), rollNo_(rollNo) {
    }

    string& getName() {
        return name_;
    }

    void setName(string name) {
        name_ = move(name);
    }

    int getRollNo() {
        return rollNo_;
    }

    void setRollNo(int rollNo) {
        rollNo_ = rollNo;
    }

private:
    string name_;
    int rollNo_;
};



/*
\ brief:  学生
\ author: 清晨与猫鱼
*/
class StudentBO {
public:
    explicit StudentBO() {
        students_.emplace_back("Robert",0);
        students_.emplace_back("John",1);
    }

    void deleteStudent(StudentVO& student) {
        cout << "Student: Roll No " << student.getRollNo() << ", deleted from database" << endl;
        students_.remove_if([&](StudentVO& stu){
            return stu.getRollNo() == student.getRollNo();
        });
    }

    StudentVO* getStudent(int rollNo) {
        auto it = find_if(students_.begin(), students_.end(), [=](StudentVO& stu) {
                    return stu.getRollNo() == rollNo;
                  });

        if (it != students_.end()) {
            return &*it;
        }

        return nullptr;
    }

    list<StudentVO>& getAllStudents() {
        return students_;
    }

    void updateStudent(StudentVO& student) {
        auto it = find_if(students_.begin(), students_.end(), [&](StudentVO& stu) {
                    return stu.getRollNo() == student.getRollNo();
                });

        if (it != students_.end()) {
            it->setName(student.getName());
        }
    }

private:
    list<StudentVO> students_;

};







